package com.example.testapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;

public class KeyEventTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_key_event_test);
    }

    // 按下

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        Log.e("TAG","onKeyDown() action=" + event.getAction()+"code=" + event.getKeyCode());
        return super.onKeyDown(keyCode, event);
    }
    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        Log.e("TAG", "onKeyUp() action="+event.getAction()+" code="+event.getKeyCode());

        return super.onKeyUp(keyCode, event); //不执行super就可以不退出界面
        //return true;
    }

    @Override
    public boolean onKeyLongPress(int keyCode, KeyEvent event) {
        Log.i("TAG", "onKeyLongPress() action="+event.getAction()+" code="+event.getKeyCode());
        return super.onKeyLongPress(keyCode, event);
    }


}